package com.ruicar.afs.cloud.apply.contract.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruicar.afs.cloud.apply.common.entity.ApplyCustAddressDetails;
import com.ruicar.afs.cloud.apply.contract.mapper.ApplyCustAddressDetailsMapper;
import com.ruicar.afs.cloud.apply.contract.service.ApplyCustAddressDetailsService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: Lee
 * @date: 2020/5/20 17:20
 * @description:
 */
@Service
public class ApplyCustAddressDetailsServiceImpl extends ServiceImpl<ApplyCustAddressDetailsMapper, ApplyCustAddressDetails> implements ApplyCustAddressDetailsService {

    /**
     * 取最新一条客户联系人数据
     * @param custId,addressType
     * @param addressType
     * @return
     */
    @Override
    public ApplyCustAddressDetails getApplyCustAddressDetails(Long custId, String addressType) {

        ApplyCustAddressDetails applyCustAddressDetails = null;
        List<ApplyCustAddressDetails> list = this.baseMapper.selectList(Wrappers.<ApplyCustAddressDetails>query().lambda()
                .eq(ApplyCustAddressDetails::getCustId, custId).eq(ApplyCustAddressDetails::getAddressType,addressType).orderByDesc(ApplyCustAddressDetails::getCreateTime));
        if(list!=null && list.size()>0){
            applyCustAddressDetails = list.get(0);
        }
        return applyCustAddressDetails;
    }
}
